using UnityEngine;
using System.Collections;
using CorruptedSmileStudio.MessageBox;

public class gameSceneUI : MonoBehaviour {

    public float labelWidthPercent = 0.2f;
    public float labelHeightPercent = 0.1f;
    public float percentBack = 0.05f;
    public float percentSpacing = 0.02f;

    private bool messageBoxShowing = false;

    public Texture backImage;

    public GUIStyle displayStyle;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	}

    void OnGUI()
    {
        int xCenter = Screen.width / 2;
        int yCenter = Screen.height / 2;

        int labelWidth = (int)(Screen.width * labelWidthPercent);
        int labelHeight = (int)(Screen.height * labelHeightPercent);

        GUI.Label(new Rect(xCenter - labelWidth / 2, yCenter - labelHeight / 2, labelWidth, labelHeight), "This is the game scene. Whee.", displayStyle);

        int xSpacing = (int)(percentSpacing * Screen.width);
        if (GUI.Button(new Rect(Screen.width - Screen.width * percentBack - xSpacing, Screen.height * percentSpacing, Screen.width * percentBack, Screen.width * percentBack), new GUIContent(backImage)))
        {
            Application.LoadLevel("mainMenu");
        }

        if (Event.current.type == EventType.KeyDown && Input.GetKeyDown(KeyCode.Escape))
        {
            if (messageBoxShowing)
            {
                print("message box is already showing");
                MessageBox.ExternalCancel();
                messageBoxShowing = false;
            }
            else
            {
                print("bringing up message box");
                MessageBox.Show(HandleLeaveDialog, "Are you sure you want to quit and go back to the main menu?", "Leave", CorruptedSmileStudio.MessageBox.MessageBoxButtons.YesNoCancel);
                messageBoxShowing = true;
            }
        }
    }

    public void HandleLeaveDialog(DialogResult result)
    {
        print("Handling result ");
        if (result == DialogResult.Yes)
            Application.LoadLevel("mainMenu");
        messageBoxShowing = false;

    }
}
